<template>
  <!--贵宾厅详情-->
  <div>
    <swiper :imgList="imgList"></swiper>
    <p class="names">{{goods.goodsName}}</p>
    <!--从积分商城进来时没有价格-->
    <ul class="price" v-if="isIntegral">
      <li>原价：{{goods.goodsPrice}}元</li>
      <li><span style="color: #ff8551">优享价：{{goods.vipPrice}}元</span><span class="xiaoliang">销量：{{goods.sales}}</span></li>
    </ul>
    <div class="bgeee">
      <ul class="address">
        <li><img src="../../../assets/clock.png" alt="" width="15"><span>{{goods.roomTime}}</span></li>
        <li><span><img src="../../../assets/address.png" alt="" width="15"></span>
          <span>{{goods.roomAddress}}</span></li>
        <li>
        <span><img src="../../../assets/noyuyue.png" alt="" width="15">
          <span v-if="goods.isAppoint==1">无需预约</span>
          <span v-if="goods.isAppoint==2">需预约</span>
        </span>
         <!-- <span><img src="../../../assets/call.png" alt="" width="14">{{goods.roomPhone}}</span>-->
        </li>
      </ul>
      <ul class="shebei" v-if="goods.viproomServerList !== undefined && goods.viproomServerList.length >0">
        <li v-for="item in goods.viproomServerList">
          <p><img :src="item.serverIcon | imgPathFilter" alt="" width="26"></p>{{item.serverName}}
        </li>
      </ul>
      <ul class="note">
        <div v-html="goods.goodsDesc"></div>
      </ul>
      <!--从首页进来时-->
      <ul class="bottom" v-if="entrySource=='home'">
        <li v-if="isOld"><p>￥{{goods.vipPrice}}</p>支付金额</li>
        <li v-else><p>￥{{goods.goodsPrice}}</p>支付金额</li>
        <li>
          <wv-button type="default" :plain="true" @click="gobuy(goods)">单次购买</wv-button>
        </li>
        <li>
          <wv-button type="default" :plain="true" @click="goUse(goods)" v-if="goods.isAppoint==1">会员免费使用</wv-button>
          <wv-button type="default" :plain="true" @click="goUse(goods)" v-if="goods.isAppoint==2">会员免费预约</wv-button>
        </li>
      </ul>
      <!--从积分商城进来时-->
      <ul class="bottom" v-if="entrySource=='integralshop'">
        <li><p>￥{{goods.integralValue}}</p>支付积分</li>
        <li>
          <wv-button type="default" :plain="true" @click="isVisible=true">兑换</wv-button>
        </li>
      </ul>
      <!--从商城进来时-->
      <gouwuche v-if="entrySource=='shop'" :cartParams="cartParams" :goods="goods" :isOld="isOld"></gouwuche>
    </div>
    <div class="model" v-if="isVisible">
      <div class="bg"></div>
      <div class="modelContent">
        <img src="../../../assets/close.png" width="15" @click="isVisible=false">
        兑换后将会扣除商品对应的积分， 是否确定兑换？
        <p class="btn">
          <button @click="goExchange(goods)">确认兑换</button>
          <button @click="isVisible=false">取消兑换</button>
        </p>
      </div>
      <div class="modelContent buzu" style="display:none;">
        <img src="../../../assets/close.png" width="15" @click="isVisible=false">
        对不起，您的积分不足，无法兑换
        <p class="btn">
          <button @click="isVisible=false">确定</button>
        </p>
      </div>
    </div>
    <div class="model" v-if="showNotCanUse">
      <div class="bg"></div>
      <div class="modelContent" v-if="vipCardState!=1">
        <img src="../../../assets/close.png" width="15" @click="showNotCanUse=false">
        {{tipContent}}
        <p class="btn">
          <button @click="showNotCanUse=false">返回</button>
          <button @click="goBuyVip()">购买</button>
        </p>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import swiper from '../../offertemplate/imgswipertemplate'
  import {getViproomDetail, exchangeGoods, queryUserVipCard} from '../../../../test/unit/http'
  import {wxApi} from '../../../../test/unit/flyme_weixin'
  import {Toast} from 'we-vue'
  import gouwuche from '../../offertemplate/gouwuche'
  import global from '../../../../test/unit/global'
  import QRCode from 'qrcodejs2'

  export default {
    name: 'guibindetail',
    props: {},
    data() {
      return {
        imgList: [],
        yuyue: '需预约',
        titles: '北京首都机场贵宾厅',
        isIntegral: true,
        isVisible: false,
        goods: {},
        entrySource: 'home',
        cartParams: {'desc': '立即预订'},
        isOld: false,
        vipCardState: 0,
        tipContent: '',
        showNotCanUse: false
      };
    },
    methods: {
      getQrCode(content) {
        let qrcode = new QRCode('qrcode', {
          width: 200, // 设置宽度，单位像素
          height: 200, // 设置高度，单位像素
          text: content
        })
      },
      gobuy(goods) {
        if (goods.isAppoint == 1) {
          this.$router.push({path: '/submitorder', query: {goodsId: goods.goodsId}})
        }
        if (goods.isAppoint == 2) {
          this.$router.push({path: '/xuyuyue', query: {goodsId: goods.goodsId, appointType: 1, maxTime: goods.maxTime,airportName:goods.airportName}})
        }
      },
      goUse(goods) {
        console.log(goods);
        let params = {goodsId: goods.goodsId};
        queryUserVipCard(params).then(res => {
          if (res.code == 100) {
            let data = res.object;
            let isHaveCanUseVipCard = data.isHaveCanUseVipCard;
            if (isHaveCanUseVipCard) {
              let accountgoods = data.accountgoods;
              let vipServerIsExpre = data.vipServerIsExpre;
              let accountGoodsId = accountgoods.accountGoodsId;
              if (vipServerIsExpre) {
                this.tipContent = '机场贵宾服务已过期，如需继续尊享请续卡';
                this.showNotCanUse = true;
                return;
              }
              if (accountgoods.isPrivatedata == 2) {
                this.$router.push({path: 'wanshanziliao', query: {accountGoodsId: accountGoodsId, type: 1}});
                return;
              }
              if (goods.isAppoint == 1) {
                this.$router.push({path: 'saomadetail', query: {accountGoodsId: accountGoodsId}})
              }
              if (goods.isAppoint == 2) {
                this.$router.push({path: 'huiyuanyuyue', query: {accountGoodsId: accountGoodsId, goodsId: goods.goodsId, appointType: 1, maxTime: goods.maxTime,airportName:goods.airportName}})
              }
            } else {
              this.tipContent = '您没有能在该贵宾厅使用的会员卡，无法免费使用，如需使用可办理会员免费使用，也可返回购买单次服务使用';
              this.showNotCanUse = true;

            }
          }
        })
      },
      goBuyVip() {
        let recommendVipcardId = this.goods.recommendVipcardId;
        if (this.$myUtils.isNull(recommendVipcardId)) {
          this.$router.push({path: 'guibinka', query: {categoryId: 1}});
        } else {
          this.$router.push({path: 'jinkadetail', query: {goodsId: recommendVipcardId}});
        }
      },
      goExchange(goods) {
        let params = {integral: goods.integralValue, goodsId: goods.goodsId, balanceType: 2, type: 3};
        exchangeGoods(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.$router.push({path: '/jifenjilu'});
          } else {
            Toast.fail(res.info);
          }
        })
      },
      getGoodsDetail(params) {
        getViproomDetail(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            let goods = res.object.viproom;
            this.goods = goods;
            let goodsImg = goods.goodsImg;
            if (!this.$myUtils.isNull(goodsImg)) {
              this.imgList = goodsImg.split(',');
            }
            this.isOld = res.object.isOld;
            this.cartParams['categoryCode'] = 'viproom';
            this.cartParams['isAppoint'] = this.goods.isAppoint;
            this.cartParams['appointType'] = 1;
          } else {
            Toast.fail(res.info)
          }
        })
      }
    },
    created() {
      let goodsId = this.$route.query.goodsId;
      let params = {goodsId: goodsId};
      this.getGoodsDetail(params);
      this.entrySource = this.$route.query.entrySource;
      if (this.entrySource == 'integralshop') {
        this.isIntegral = false;
      }
      let url = window.location.href;
      let shareUrl = this.$myUtils.initShareUrl(url);
      let that = this;
      wxApi.init(function () {
        wxApi.updateAppMessageShareData(that.goods.goodsName, that.goods.goodsName, shareUrl, global.ImgBaseURL + '/' + that.goods.coverImg)
      });
    },
    beforeRouteLeave(to, form, next) {
      let activeIndex = form.query.activeIndex;
      if(activeIndex){
        to.query.activeIndex=activeIndex;
      }
      next()
    },
    components: {
      swiper,
      gouwuche
    }
  }
</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .names {
    font-size: 18px;
    color: #111;
    font-weight: 700;
    padding: 10px;
    text-align: left;
  }

  .price {
    padding: 10px;
    text-align: left;

    li:first-child {
      font-size: 15px;
      color: #999;
    }

    li:last-child {
      font-size: 15px;
      color: #000;
      font-weight: 700;

      .xiaoliang {
        float: right;
        font-size: 12px;
        color: #999;
      }
    }
  }

  .bgeee {
    background-color: #eee;
    font-size: 12px;
    color: #666;
    text-align: left;
    padding-top: 10px;

    .address {
      background-color: #fff;
      padding: 10px;

      li {
        display: flex;
        align-items: center;
        padding: 10px 0;
        border-bottom: 1px solid #eee;

        img {
          margin-right: 5px;
        }

        span {
          line-height: 22px;
        }
      }

      li:nth-child(2) {
        display: flex;
        padding: 10px 0;
        height: auto;
        align-items: center;

        span:first-child {
          flex: 0 20px;

          img {
            vertical-align: top;
            padding-top: 5px;
          }
        }

        span:last-child {
          line-height: 22px;
        }
      }

      li:last-child {
        display: flex;
        border-bottom: none;

        span {
          flex: 1;
        }

        :first-child {
          color: #e96775;
        }
      }
    }

    .shebei {
      background-color: #fff;
      margin: 10px;
      border-radius: 4px;
      display: flex;
      padding: 20px 10px 10px;
      flex-wrap: wrap;

      li {
        width: 25%;
        text-align: center;
        font-size: 12px;
        color: #666;
        margin-bottom: 10px;

        p {
          height: 30px;
        }
      }
    }

    .note {
      background-color: #fff;
      padding: 10px 10px 85px;
      margin-bottom: 85px;

      li {
        font-size: 14px;
        color: #666;
        margin-bottom: 10px;

        p {
          font-size: 16px;
          color: #111;
          font-weight: 700;
        }
      }
    }

    .bottom {
      background-color: #eee;
      display: flex;
      padding: 10px;
      position: fixed;
      bottom: 0;
      width: 100%;

      li {
        flex: 1;

      }

      :first-child {
        font-size: 12px;
        color: #999;

        p {
          color: #fc8d4e;
          font-size: 18px;
        }
      }

      :nth-child(2) {
        button {
          background-image: linear-gradient(to left, #ff8551, #f9964e);
          color: #fff;
          height: 40px;
          line-height: 30px;
          border-radius: 5px;
          border: none;
          width: 120px;
        }
      }

      :last-child {
        button {
          background-image: linear-gradient(to left, #ff8551, #f9964e);
          color: #fff;
          height: 40px;
          margin-left: 5px;
          line-height: 30px;
          border-radius: 5px;
          border: none;
          width: 120px;
          margin-right: 20px;
        }
      }
    }
  }

  .bg {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model .modelContent {
    background-color: #fff;
    border-radius: 8px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -43%;
    margin-top: -111px;
    z-index: 2;
    padding: 40px 10px 20px;
    width: 80%;
    text-align: left;

    img {
      position: absolute;
      right: 10px;
      top: 10px
    }

    .btn {
      button {
        height: 42px;
        line-height: 42px;
        color: #fff;
        outline: none;
        border: none;
        width: calc(50% - 20px);
        border-radius: 8px;
        margin-top: 25px;
      }

      :last-child {
        background-color: #f9964e;

      }

      :first-child {
        background-color: #ccc;
        margin-right: 20px;

      }
    }

  }

  .model .buzu {
    text-align: center;

    .btn button {
      width: 100%;
    }
  }
</style>
